<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<c:set var="buttons">
    <input type="button" style="margin-right: 5px"   onclick="f_add()" value="<fmt:message key="button.add"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_update()" value="<fmt:message key="button.update"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_delete()" value="<fmt:message key="button.delete"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_cancel()" value="<fmt:message key="button.cancel"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_save()" value="<fmt:message key="button.save"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_query()" value="<fmt:message key="button.query"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_excel()" value="<fmt:message key="button.excel"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_evItem()" value="<fmt:message key="button.ev.item"/>"/>
<c:if test='${not empty model.parentId}'>
    <input type="button" style="margin-right: 5px"   onclick="f_back()" value="<fmt:message key="button.back"/>"/>
</c:if> 
</c:set> 
<div id='toolbar' style="display:none">
<c:out value="${buttons}" escapeXml="false"/>
</div>
<div id="parameter_form" align=center></div> 
<script>
var form,year,semester,courseType;
Ext.onReady(globalScope._ready);

Ext.onReady(function(){
  Ext.get('title').dom.style.display='none';
	var yearStore=new Ext.data.SimpleStore({
     'fields':['value','text'],
     data:<c:out value="${model.yearJson}" escapeXml='false' />
	});
	var semesterStore=new Ext.data.SimpleStore({
     'fields':['value','text'],
     data:<c:out value="${model.semesterJson}" escapeXml='false' />
	});
	var courseTypeStore=new Ext.data.SimpleStore({
     'fields':['value','text'],
     data:<c:out value="${model.courseTypeJson}" escapeXml='false' />
	});
	
	var currentYear="<c:out value='${model.currentYear}'/>";
	var currentSemester="<c:out value='${model.currentSemester}'/>";

	form = new Ext.form.FormPanel({
	     el:'parameter_form',
  		labelAlign:'right',
	    frame:true,
	    border:true,
	    height:40,
	    items:[{
	          layout:'column',
	          items:[{
	            layout:'form',
	            columnWidth:1/4,
	            items:[{
			            xtype:'combo',   
			            fieldLabel:'学年度',  
			            store: yearStore,   
			            editable: false,   
			            mode: 'local',   
			            hiddenName:'SCHOOL_YEAR',   
			            id:'_SCHOOL_YEAR',   
			            displayField:'text',   
			            valueField:'value',
			            triggerAction: 'all', 
			            emptyText:'请选择',   
			            value:currentYear,  
			            width:200         
			         }
	         ]},{
	           layout:'form',
	           columnWidth:1/4,
	           items:[
			         {
			            xtype:'combo',   
			            fieldLabel:'学期',   
			            store: semesterStore,   
			            mode: 'local',   
			            hiddenName:'SCHOOL_SEMESTER',   
			            id:'_SCHOOL_SEMESTER',   
			            displayField:'text',   
			            valueField:'value',   
			            triggerAction: 'all',   
			            value:currentSemester,
			            emptyText:'请选择', 
			            width:200         
			         }
            ]},{
	           layout:'form',
	           columnWidth:1/4,
	           items:[
			         {
			            xtype:'combo',   
			            fieldLabel:'课程类型',   
			            store: courseTypeStore,   
			            mode: 'local',   
			            hiddenName:'COURSE_TYPE',   
			            id:'_COURSE_TYPE',   
			            displayField:'text',   
			            valueField:'value',   
			            triggerAction: 'all',   
			            emptyText:'请选择',   
			            value:courseTypeStore.getAt(0).get("value"),
			            width:200         
			         }
            ]},{
	           layout:'form',
	           columnWidth:1/4,
	           items:[
			         {
			            xtype:'button',   
			            text:'确定',
			            width:200,
			            handler:queryIndex        
			         }
            ]}
          ]  
         }
       ]  
	});
   form.render();
   queryIndex();

  
});


  var tableName="<c:out value='${model.parameter.tableName}'/>";
function queryIndex(){
   var yearCombo=form.getForm().findField('_SCHOOL_YEAR');
   var semesterCombo=form.getForm().findField('_SCHOOL_SEMESTER');
   var courseTypeCombo=form.getForm().findField('_COURSE_TYPE');
   year=yearCombo.getValue();
   semester=semesterCombo.getValue();
   courseType=courseTypeCombo.getValue();
   globalScope._changeQuickCookie("SCHOOL_YEAR",year);
   globalScope._changeQuickCookie("SCHOOL_SEMESTER",semester);
   globalScope._changeQuickCookie("COURSE_TYPE",courseType);
   
    globalScope._model({tableName:tableName,SCHOOL_YEAR:year,SCHOOL_SEMESTER:semester,COURSE_TYPE:courseType},function(responseText){
    var htmlDiv=Ext.get("table_html").dom;
    htmlDiv.innerHTML=responseText;
    var htmlTable=Ext.get(tableName);
    globalScope.grid.get(tableName).reloadData(htmlTable);	
  },false);  
}

<c:if test='${not empty model.parentId}'>
function f_back(){
   history.back();
}
</c:if>
function f_evItem(){
	  var r=globalScope.grid.get(tableName).getSelectionModel().getSelected();
	  if(Ext.isEmpty(r)){
	    Ext.Msg.alert('WARNING',jspVarHandler.fmt_info_required_update_record);
	    return false;
	  }
   var matrix=[["tableName","T_EV_ITEM"],["REFID",r.id]];
   var form=createForm("<c:url value='/quick/quickWithParentInfo.html'/>",matrix);
   form.submit(); 
}

function f_excel(){
  globalScope._exportExcel();
//  globalScope._excel();
}

function f_add(tableName){
  globalScope._add(tableName);
}

function f_update(tableName){
  globalScope._update(tableName);
}

function f_delete(tableName){
  globalScope._delete(tableName);
} 

function f_cancel(tableName){
  globalScope._cancel(tableName);
}

function f_save(tableName,url){
  globalScope._save(tableName,url);
}

function f_query(tableName){
    globalScope._query(tableName);
}
function f_gotoPage(pageNo,rowsOfPage,pageCount,rowCount,conditoin){
  globalScope._gotoPage({spanName:"g_pageSpan_<c:out value='${model.tableName}'/>",pageNo:pageNo,rowsOfPage:rowsOfPage,pageCount:pageCount,rowCount:rowCount,condition:conditoin,tableName:"<c:out value='${model.tableName}'/>"});
}
</script>
